import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class PokerTest {
    private Deck deck;
    private Hand hand;
    private Hand hand1;
    private Hand hand2;
    private Hand hand3;
    private Hand hand4;
    private Hand hand5;
    private Hand hand6;
    @Before
    public final void setUp() throws Exception {
        deck = new Deck();
        hand = new Hand();
        hand1 = new Hand();
        hand2 = new Hand();
        hand3 = new Hand();
        hand4 = new Hand();
        hand5 = new Hand();
        hand6 = new Hand();
        hand1.cardAdd(2, 'd');
        hand1.cardAdd(11, 's');
        hand1.cardAdd(5, 'h');
        hand1.cardAdd(8, 's');
        hand1.cardAdd(9, 's');
        hand2.cardAdd(2, 's');
        hand2.cardAdd(4, 's');
        hand2.cardAdd(5, 's');
        hand2.cardAdd(8, 's');
        hand2.cardAdd(9, 's');
        hand3.cardAdd(2, 'h');
        hand3.cardAdd(5, 'd');
        hand3.cardAdd(5, 's');
        hand3.cardAdd(8, 'c');
        hand3.cardAdd(5, 's');
        hand4.cardAdd(2, 's');
        hand4.cardAdd(3, 's');
        hand4.cardAdd(4, 's');
        hand4.cardAdd(5, 's');
        hand4.cardAdd(6, 's');
        hand5.cardAdd(7, 'c');
        hand5.cardAdd(9, 'd');
        hand5.cardAdd(7, 'h');
        hand5.cardAdd(7, 's');
        hand5.cardAdd(11, 's');
        hand6.cardAdd(7, 'c');
        hand6.cardAdd(9, 'd');
        hand6.cardAdd(7, 'h');
        hand6.cardAdd(7, 's');
        hand6.cardAdd(10, 'c');
    }

    @After
    public final void tearDown() throws Exception {
        deck = null;
        hand1 = null;
        hand2 = null;
        hand3 = null;
        hand4 = null;
        hand5 = null;
        hand6 = null;
    }

    @Test(timeout = 10)
    public final void testShufflingTime() {
        deck.shuffle();
    }
    
    @Test(expected = PokerException.class)
    public final void cardException() throws PokerException {
           Card card = new Card(14, 'c');
    }
    
    @Test(expected = PokerException.class)
    public final void tableException() throws PokerException {
        Table table = new Table(3, 4, 100, 20);
    }
    
    @Test
    public final void testDrawCard() {
        hand.cardPick(deck);
        int rank = 0;
        char suit = 'x';
        try {
            suit = hand.getCard(0).getSuit();
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            rank = hand.getCard(0).getRank();
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        assertFalse("Card illegaly found!", deck.findCard(rank, suit));
    }
    
    @Test
    public final void testFlushEvaluation() {
        try {
            assertTrue("Wrong evaluation!", hand2.getHandRank() == 5);
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Test
    public final void testHCEvaluation() {
        try {
            assertTrue("Wrong evaluation!", hand1.getHandRank() == 0);
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Test
    public final void testThreeEvaluation() {
        try {
            assertTrue("Wrong evaluation!", hand3.getHandRank() == 3);
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Test
    public final void testStraightFlushEvaluation() {

        try {
            assertTrue("Wrong evaluation!", hand4.getHandRank() == 8);
        } catch (PokerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    @Test
    public final void equalityTest() {

        assertTrue("Not equal!", hand6.compareTo(hand5) == 0);
    }
    
    @Test 
    public final void compareTest() {
        assertTrue("Wrong compare!", hand2.compareTo(hand3) > 0);
    }
    
}
